<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.gouwudai.gobbs.pojo.TbbsClass"%>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限管理模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断用户类型 START
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
//判断用户类型 END
if(operatorType<2)
{
	HtmlConst.errors(out,1,"您不是该版的版主，没有当前操作的权限！");
	return;
}
	
userLogin.hasClassPermission(new Integer(classId),4008);//添加认证用户	
/***************** 权限管理模块 END *********************/
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
/***************************************************/

List notHaveList = classUserService.listAllUserClassNotHave(classId,new Integer(1));
request.setAttribute("notHaveList",notHaveList);
%>
<HTML>
<HEAD>
<title>添加认证用户</title>
<%@ include file="../common/meta.inc" %>
<link href="css/defaultStyle.css" rel="stylesheet" type="text/css">
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
<script language="javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);
function doSubmit() {

	form = document.theform;
	
	if(!validateForm(form))
		return;
		
	var classUserArray = new Array();
	
	var userIdOptionLen = form.haveId.options.length;
	for(i=0;i< userIdOptionLen; i++)
	{
		var userIdOption = form.haveId.options(i);
		var obj = {};
		obj[Buffalo.BOCLASS] = "com.gouwudai.gobbs.pojo.TbbsClassUser";
		obj.userId=parseInt(userIdOption.value);
		obj.userType=1;
		obj.classId=<%=classId%>;	
		classUserArray.push(obj);
	}	
    
    buffalo.remoteCall("classUserServiceAjaxService.saveBatch",[classUserArray], function(reply) {
        ajaxSubmit(reply.getResult(),"保存成功！","back");
    });
}

function validateForm(form)
{	
	var count = form.haveId.options.length;
	if(count<=0)
	{
		sl_alert("请先选择认证用户！");
		return false;
	} 
    return sl_confirmUpdate();
}

</script>
</HEAD>
<BODY leftMargin=0 topMargin=0 rightmargin="0" bottommargin="0">
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">
setStatus('<%=SYSTITLE%> - <%=totalClassName.toString() %> - 添加认证用户');
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
	<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;添加认证用户
</DIV>
<DIV class="line"></DIV>
<jsp:include flush="true" page="css/class_manage_menu.jsp?classId=<%=classId %>"></jsp:include>
<form name="theform" method="post">
<table class="bluetable" width="100%" cellpadding="1" cellspacing="1">	
	<tr>
	    <th colspan="2">添加认证用户</th>
	</tr>							
	<tr>
		<td class="title" align="right">用户列表:</td>
		<td>
			<table width="100%">
				<tr>
					<td class="title" align="center">用户列表</td>
					<td class="title" align="center">&nbsp;</td>
					<td class="title" align="center">认证用户列表</td>
				</tr>
				<tr>
					<td><select name="notHaveId" id="notHaveId" size="15" multiple="multiple" style="width:300px;">
							<c:forEach items="${notHaveList}" var="userInfo">
									<option value="${userInfo.userId }">${userInfo.loginId } - ${userInfo.userName }</option>
							</c:forEach>
						</select></td>
					<td><table width="100%">
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveOne(document.theform.notHaveId,document.theform.haveId);">&gt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveAll(document.theform.notHaveId,document.theform.haveId);">&gt;&gt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveOne(document.theform.haveId,document.theform.notHaveId);">&lt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveAll(document.theform.haveId,document.theform.notHaveId);">&lt;&lt;</button></td>
								</tr>
							</table></td>
					<td><select name="haveId" id="haveId" size="15" multiple="multiple" style="width:300px;">											
						</select></td>
				</tr>
			</table>
		</td>
	</tr>																															
</table>
<table border="0" width="100%">
	<tr>
		<td align="right">
		<button class="btn" accessKey=s id="btnSave" name="btnSave" onclick="javascript:doSubmit();">保存(<u>S</u>)</button>
		&nbsp;&nbsp;
		<button class="btn" accessKey=c id="btnCancel" name="btnCancel" onclick="javascript:history.back();">取消(<u>C</u>)</button>
		&nbsp;&nbsp;								
		</td>
	</tr>
</table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>	
</BODY>
</HTML>

